package slap.http.websocket;

import slap.paradigm.F;
import slap.paradigm.F.Option;
import slap.paradigm.Matcher;

public class WebSocketEvent {

	public static Matcher<WebSocketEvent, WebSocketClose> SocketClosed = new Matcher<WebSocketEvent, WebSocketClose>() {

		@Override
		public F.Option<WebSocketClose> match(WebSocketEvent o) {
			if (o instanceof WebSocketClose) {
				return Option.Some((WebSocketClose) o);
			}
			return F.Option.None();
		}
	};
	public static Matcher<WebSocketEvent, String> TextFrame = new Matcher<WebSocketEvent, String>() {

		@Override
		public Option<String> match(WebSocketEvent o) {
			if (o instanceof WebSocketFrame) {
				WebSocketFrame frame = (WebSocketFrame) o;
				if (!frame.isBinary) {
					return F.Option.Some(frame.textData);
				}
			}
			return F.Option.None();
		}
	};
	public static Matcher<WebSocketEvent, byte[]> BinaryFrame = new Matcher<WebSocketEvent, byte[]>() {

		@Override
		public Option<byte[]> match(WebSocketEvent o) {
			if (o instanceof WebSocketFrame) {
				WebSocketFrame frame = (WebSocketFrame) o;
				if (frame.isBinary) {
					return F.Option.Some(frame.binaryData);
				}
			}
			return F.Option.None();
		}
	};
}